<?php
/**
 * common repository file Created by PhpStorm.
 * User: wumengmeng
 * Date: 2019/08/20
 * Time: 06:07
 */

namespace HiCommon\Repository;

use HiCommon\Model\Repairstore;

class RepairstoreRepository extends BaseRepository
{
    public function base_model()
    {
        return new \HiCommon\Model\Repairstore();
    }

    /**
     * 分页获取数据
     *
     * @param array $arr_option
     *
     * @return mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function get_list($search = [])
    {
        $model = new Repairstore();
        if (isset($search['name']) && $search['name']) {
            $model = $model->where('name', 'like', '%' . $search['name'] . '%');
        }
        if (isset($search['phone']) && $search['phone']) {
            $model = $model->where('phone', $search['phone']);
        }

        return $model->commonpage($search);
    }


    /**
     * 查询一条数据
     *
     * @param int $n_id
     * @param array $arr_option
     *
     * @return mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function get_one(int $n_id, $arr_option = [])
    {
        return Repairstore::commonfind($n_id, $arr_option);
    }

    /**
     * 根据条件查询一条数据
     */
    public function get_where_one(array $where = [])
    {
        return Repairstore::where($where)->with(['shop_img'])->first();
    }

    /**
     * 修改或添加一条数据
     *
     * @param array $arr_input
     *
     * @return mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function edit_or_create(array $arr_where, array $arr_input)
    {
        return Repairstore::updateorcreate($arr_where, $arr_input);
    }

    /**
     * 修改一条数据
     *
     * @param array $arr_input
     *
     * @return mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function edit_one(array $arr_input)
    {
        return Repairstore::where('id', $arr_input['id'])->update($arr_input);
    }

    /**
     * 删除一条数据
     *
     * @param int $n_id
     *
     * @return mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function delete_one(int $n_id)
    {
        return Repairstore::where('id', $n_id)->commondelete();
    }

    /**
     * 修改一条数据状态
     *
     * @param int $n_id
     * @param int $n_state
     *
     * @return mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function change_one_state(int $n_id, int $n_state)
    {
        return Repairstore::where('id', $n_id)->update(['state' => $n_state]);

    }


}